package offer;

@FunctionalInterface
public interface ConvertToBase7 {
    /**
     * Given an integer num, return a string of its base 7 representation.
     * @param num       input integer
     * @return          output 7 base number, String format
     */
    String convertToBase7(int num);
}

class ConvertToBase7Impl1 implements ConvertToBase7{

    @Override
    public String convertToBase7(int num) {
        if(num == 0){
            return ""+0;
        }
        StringBuilder ans = new StringBuilder();
        boolean isPositive = true;
        if(num < 0){
            isPositive = false;
            num = -num;
        }
        while(num != 0){
            ans.append(num % 7);
            num /= 7;
        }
        ans.reverse();
        if(!isPositive){
            ans.insert(0, '-');
        }
        return ans.toString();
    }
}
